package Z_exchange;

import com.rabbitmq.client.Channel;
import utils.RabbitMQUtils;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

import static Z_exchange.MqConst.EXCHANGE_NAME;

/**
 * @author： pang-yun
 * @date： 2021-12-15 16:44
 * 功能目的 ：用于 生产者
 */

public class EmitLog {
    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbitMQUtils.getChannel();

        // exchange 声明为 fanout 即 发布订阅模式
        channel.exchangeDeclare(EXCHANGE_NAME, MqConst.TypeMy.FAN_OUT.getValue());

        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String message = scanner.next();
            channel.basicPublish(EXCHANGE_NAME,"",null,message.getBytes(StandardCharsets.UTF_8));
            System.out.println("发送成功: "+message);

        }

    }
}
